/*
* Copyright 2017 Yonyou Auto Information Technology（Shanghai） Co., Ltd. All Rights Reserved.
*
* This software is published under the terms of the YONYOU Software
* License version 1.0, a copy of which has been included with this
* distribution in the LICENSE.txt file.
*
* @Project Name : marketing-service-dealer
*
* @File name : TestDrivingController.java
*
* @Author : Administrator
*
* @Date : 2017年12月5日
*
----------------------------------------------------------------------------------
*     Date       Who       Version     Comments
* 1. 2017年12月5日    Administrator    1.0
*
*
*
*
----------------------------------------------------------------------------------
*/

package com.yonyou.gmmc.service.dealer.controller;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.log4j.Logger;
import org.marketing.common.constants.ResultMsgConstants;
import org.marketing.common.util.CheckUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.github.pagehelper.PageInfo;
import org.marketing.common.Response;
import com.yonyou.gmmc.service.dealer.constant.DealerConstant;
import com.yonyou.gmmc.service.dealer.entity.EvaluationPO;
import com.yonyou.gmmc.service.dealer.entity.TestdrivePO;
import com.yonyou.gmmc.service.dealer.model.TmDealer;
import com.yonyou.gmmc.service.dealer.model.TmUsers;
import com.yonyou.gmmc.service.dealer.model.TmVirtualCenter;
import com.yonyou.gmmc.service.dealer.model.TrDriveGoodsRelation;
import com.yonyou.gmmc.service.dealer.model.TtDriveGoods;
import com.yonyou.gmmc.service.dealer.model.TtDriveInfo;
import com.yonyou.gmmc.service.dealer.model.TtTestdrive;
import com.yonyou.gmmc.service.dealer.service.TestDrivingService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * @author Administrator 企业号试驾预约API
 * @date 2017年12月5日
 */
@RestController
@RequestMapping(value = DealerConstant.BASE_PATH + "/" + DealerConstant.VERSION)
@Api("企业号试驾预约API")
public class TestDrivingController {

    private Logger             logger = Logger.getLogger(TestDrivingController.class);

    @Autowired
    private TestDrivingService testDrivingService;

    @RequestMapping(value = "/driverList", method = RequestMethod.GET, produces = "application/json;charset=UTF-8")
    @ApiOperation(value = "PC-查询试驾预约列表", notes = "PC-查询试驾预约列表")
    @CrossOrigin
    public Response<PageInfo<TtTestdrive>> selectDriveList(@RequestParam(required = false, defaultValue = "1") Integer pageNum,
                                                           @RequestParam(required = false, defaultValue = "10") String pageSize,
                                                           @RequestParam(required = true, defaultValue = "") String userId,
                                                           @RequestParam(required = false, defaultValue = "") String keyWord,
                                                           @RequestParam(required = false, defaultValue = "") String modelCodeNew,
                                                           @RequestParam(required = false, defaultValue = "") String status,
                                                           @RequestParam(required = false, defaultValue = "") String dispatchObject,
                                                           @RequestParam(required = false, defaultValue = "") String manager,
                                                           @RequestParam(required = false, defaultValue = "") String counselor,
                                                           @RequestParam(required = false, defaultValue = "") String appreciationEngineer,
                                                           @RequestParam(required = false, defaultValue = "") String applyStartDate,
                                                           @RequestParam(required = false, defaultValue = "") String applyEndDate,
                                                           @RequestParam(required = false, defaultValue = "") String driveCity) throws Exception {
        Map<String, Object> query = new HashMap<String, Object>();
        try {
            query.put("pageNum", pageNum);
            query.put("pageSize", pageSize);
            query.put("userId", userId);
            if (!CheckUtil.NullOrEmpty(keyWord)) {
                query.put("keyWord", keyWord);
            }
            if (!CheckUtil.NullOrEmpty(modelCodeNew)) {
                query.put("modelCodeNew", modelCodeNew);
            }
            if (!CheckUtil.NullOrEmpty(status)) {
                query.put("status", status);
            }
            if (!CheckUtil.NullOrEmpty(dispatchObject)) {
                query.put("dispatchObject", dispatchObject);
            }
            if (!CheckUtil.NullOrEmpty(manager)) {
                query.put("manager", manager);
            }
            if (!CheckUtil.NullOrEmpty(counselor)) {
                query.put("counselor", counselor);
            }
            if (!CheckUtil.NullOrEmpty(appreciationEngineer)) {
                query.put("appreciationEngineer", appreciationEngineer);
            }
            if (!CheckUtil.NullOrEmpty(applyStartDate)) {
                query.put("applyStartDate", applyStartDate);
            }
            if (!CheckUtil.NullOrEmpty(applyEndDate)) {
                query.put("applyEndDate", applyEndDate);
            }
            if (!CheckUtil.NullOrEmpty(driveCity)) {
                query.put("driveCity", driveCity);
            }
            PageInfo<TtTestdrive> resultList = testDrivingService.selectDriveList(query);
            return new Response<PageInfo<TtTestdrive>>(ResultMsgConstants.RESULT_CODE_SUCCESS, resultList, "");
        } catch (Exception e) {
            logger.error("查询预约发生异常", e);
            return new Response<>(ResultMsgConstants.RESULT_CODE_ERROR, e.getMessage());
        }
    }

    @RequestMapping(value = "/driverInfo", method = RequestMethod.GET, produces = "application/json;charset=UTF-8")
    @ApiOperation(value = "单条试驾预约详情查询", notes = "单条试驾预约详情查询")
    @CrossOrigin
    public Response<TtTestdrive> driverInfo(@RequestParam("driveId") String driveId) throws Exception {
        TtTestdrive result = new TtTestdrive();
        try {
            result = testDrivingService.driverInfo(driveId);
            return new Response<TtTestdrive>(ResultMsgConstants.RESULT_CODE_SUCCESS, result, "");
        } catch (Exception e) {
            logger.error("试驾查询发生异常", e);
            return new Response<>(ResultMsgConstants.RESULT_CODE_ERROR, e.getMessage());
        }
    }

    @RequestMapping(value = "/driveId", method = RequestMethod.GET, produces = "application/json;charset=UTF-8")
    @ApiOperation(value = "查询新建试驾的编号", notes = "查询新建试驾的编号")
    @CrossOrigin
    public Response<String> selectDriveId() throws Exception {
        String driveId = null;
        try {
            driveId = testDrivingService.selectDriveId();
            return new Response<String>(ResultMsgConstants.RESULT_CODE_SUCCESS, driveId, "");
        } catch (Exception e) {
            logger.error("查询状态发生异常", e);
            return new Response<>(ResultMsgConstants.RESULT_CODE_ERROR, e.getMessage());
        }
    }

    @RequestMapping(value = "/city", method = RequestMethod.GET, produces = "application/json;charset=UTF-8")
    @ApiOperation(value = "省市列表", notes = "省市列表")
    @CrossOrigin
    public Response<List<Map<String, Object>>> cityList() throws Exception {
        List<Map<String, Object>> resultList = new ArrayList<Map<String, Object>>();
        try {
            resultList = testDrivingService.cityList();
            return new Response<List<Map<String, Object>>>(ResultMsgConstants.RESULT_CODE_SUCCESS, resultList, "");
        } catch (Exception e) {
            logger.error("查询状态发生异常", e);
            return new Response<>(ResultMsgConstants.RESULT_CODE_ERROR, e.getMessage());
        }
    }

    @RequestMapping(value = "/carModel", method = RequestMethod.GET, produces = "application/json;charset=UTF-8")
    @ApiOperation(value = "车型列表", notes = "车型列表")
    @CrossOrigin
    public Response<List<Map<String, String>>> carModel() throws Exception {
        List<Map<String, String>> resultList = new ArrayList<Map<String, String>>();
        try {
            resultList = testDrivingService.carModel();
            return new Response<List<Map<String, String>>>(ResultMsgConstants.RESULT_CODE_SUCCESS, resultList, "");
        } catch (Exception e) {
            logger.error("查询状态发生异常", e);
            return new Response<>(ResultMsgConstants.RESULT_CODE_ERROR, e.getMessage());
        }
    }

    @RequestMapping(value = "/status", method = RequestMethod.GET, produces = "application/json;charset=UTF-8")
    @ApiOperation(value = "PC-状态列表", notes = "PC-状态列表")
    @CrossOrigin
    public Response<List<Map<String, String>>> status() throws Exception {
        List<Map<String, String>> resultList = new ArrayList<Map<String, String>>();
        try {
            resultList = testDrivingService.status();
            return new Response<List<Map<String, String>>>(ResultMsgConstants.RESULT_CODE_SUCCESS, resultList, "");
        } catch (Exception e) {
            logger.error("查询状态发生异常", e);
            return new Response<>(ResultMsgConstants.RESULT_CODE_ERROR, e.getMessage());
        }
    }

    @RequestMapping(value = "/managers", method = RequestMethod.GET, produces = "application/json;charset=UTF-8")
    @ApiOperation(value = "PC-经理列表", notes = "PC-经理列表")
    @CrossOrigin
    public Response<List<TmUsers>> managers() throws Exception {
        List<TmUsers> resultList = new ArrayList<TmUsers>();
        try {
            resultList = testDrivingService.managers();
            return new Response<List<TmUsers>>(ResultMsgConstants.RESULT_CODE_SUCCESS, resultList, "");
        } catch (Exception e) {
            logger.error("查询状态发生异常", e);
            return new Response<>(ResultMsgConstants.RESULT_CODE_ERROR, e.getMessage());
        }
    }

    @RequestMapping(value = "/counselors", method = RequestMethod.GET, produces = "application/json;charset=UTF-8")
    @ApiOperation(value = "PC-顾问列表", notes = "PC-顾问列表")
    @CrossOrigin
    public Response<List<TmUsers>> counselors() throws Exception {
        List<TmUsers> resultList = new ArrayList<TmUsers>();
        try {
            resultList = testDrivingService.counselors();
            return new Response<List<TmUsers>>(ResultMsgConstants.RESULT_CODE_SUCCESS, resultList, "");
        } catch (Exception e) {
            logger.error("查询状态发生异常", e);
            return new Response<>(ResultMsgConstants.RESULT_CODE_ERROR, e.getMessage());
        }
    }

    @RequestMapping(value = "/engineers", method = RequestMethod.GET, produces = "application/json;charset=UTF-8")
    @ApiOperation(value = "PC-工程师列表", notes = "PC-工程师列表")
    @CrossOrigin
    public Response<List<TmUsers>> engineers() throws Exception {
        List<TmUsers> resultList = new ArrayList<TmUsers>();
        try {
            resultList = testDrivingService.engineers();
            return new Response<List<TmUsers>>(ResultMsgConstants.RESULT_CODE_SUCCESS, resultList, "");
        } catch (Exception e) {
            logger.error("查询状态发生异常", e);
            return new Response<>(ResultMsgConstants.RESULT_CODE_ERROR, e.getMessage());
        }
    }

    @RequestMapping(value = "/saveDrive", method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
    @ApiOperation(value = "保存试驾预约", notes = "保存试驾预约")
    @CrossOrigin
    public Response<Map<String, Object>> saveDrive(@RequestBody TtTestdrive ttTestdrive) throws Exception {
        Map<String, Object> result = new HashMap<String, Object>();
        try {
            result = testDrivingService.saveDrive(ttTestdrive);
            return new Response<Map<String, Object>>(ResultMsgConstants.RESULT_CODE_SUCCESS, result, "");
        } catch (Exception e) {
            logger.error("保存预约发生异常", e);
            return new Response<>(ResultMsgConstants.RESULT_CODE_ERROR, e.getMessage());
        }
    }

    @RequestMapping(value = "/resourceObject", method = RequestMethod.GET, produces = "application/json;charset=UTF-8")
    @ApiOperation(value = "查看资源-分拨对象列表", notes = "查看资源-分拨对象列表(PC也可用)")
    @CrossOrigin
    public Response<List<TmVirtualCenter>> resourceObject() throws Exception {
        List<TmVirtualCenter> resultList = new ArrayList<TmVirtualCenter>();
        try {
            resultList = testDrivingService.resourceObject();
            return new Response<List<TmVirtualCenter>>(ResultMsgConstants.RESULT_CODE_SUCCESS, resultList, "");
        } catch (Exception e) {
            logger.error("查询分拨对象列表发生异常", e);
            return new Response<>(ResultMsgConstants.RESULT_CODE_ERROR, e.getMessage());
        }
    }

    @RequestMapping(value = "/resourceDealer", method = RequestMethod.GET, produces = "application/json;charset=UTF-8")
    @ApiOperation(value = "查看资源-经销商列表", notes = "查看资源-经销商列表")
    @CrossOrigin
    public Response<List<TmDealer>> resourceDealer() throws Exception {
        List<TmDealer> resultList = new ArrayList<TmDealer>();
        try {
            resultList = testDrivingService.resourceDealer();
            return new Response<List<TmDealer>>(ResultMsgConstants.RESULT_CODE_SUCCESS, resultList, "");
        } catch (Exception e) {
            logger.error("查询经销商列表发生异常", e);
            return new Response<>(ResultMsgConstants.RESULT_CODE_ERROR, e.getMessage());
        }
    }

    @RequestMapping(value = "/resourceUsage", method = RequestMethod.GET, produces = "application/json;charset=UTF-8")
    @ApiOperation(value = "查看资源占用", notes = "查看资源占用")
    @CrossOrigin
    public Response<PageInfo<Map<String, Object>>> resourceUsage(@RequestParam(required = false, defaultValue = "1") Integer pageNum,
                                                             @RequestParam(required = false, defaultValue = "10") Integer pageSize,
                                                             @RequestParam(required = false, defaultValue = "") String date,
                                                             @RequestParam(required = false, defaultValue = "") String dispatchObject,
                                                             @RequestParam(required = false, defaultValue = "") String dealerCode,
                                                             @RequestParam(required = false, defaultValue = "") String modelCodeNew) throws Exception {
        try {
            PageInfo<Map<String, Object>> resultList = testDrivingService.resourceUsage(pageNum,pageSize,date,dispatchObject,dealerCode,modelCodeNew);
            return new Response<PageInfo<Map<String, Object>>>(ResultMsgConstants.RESULT_CODE_SUCCESS, resultList, "");
        } catch (Exception e) {
            logger.error("查询资源占用发生异常", e);
            return new Response<>(ResultMsgConstants.RESULT_CODE_ERROR, e.getMessage());
        }
    }

    @RequestMapping(value = "/dispatch", method = RequestMethod.GET, produces = "application/json;charset=UTF-8")
    @ApiOperation(value = "分拨对象列表", notes = "分拨对象列表")
    @CrossOrigin
    public Response<List<TmVirtualCenter>> dispatch(@RequestParam("driveId") String driveId) throws Exception {
        List<TmVirtualCenter> resultList = new ArrayList<TmVirtualCenter>();
        try {
            resultList = testDrivingService.dispatch(driveId);
            return new Response<List<TmVirtualCenter>>(ResultMsgConstants.RESULT_CODE_SUCCESS, resultList, "");
        } catch (Exception e) {
            logger.error("查询分拨对象列表发生异常", e);
            return new Response<>(ResultMsgConstants.RESULT_CODE_ERROR, e.getMessage());
        }
    }

    @RequestMapping(value = "/dispatchCarList", method = RequestMethod.GET, produces = "application/json;charset=UTF-8")
    @ApiOperation(value = "分拨页面-车辆列表", notes = "分拨页面-车辆列表")
    @CrossOrigin
    public Response<List<String>> dispatchCarList(@RequestParam("dispatchObject") String dispatchObject,
                                                  @RequestParam("modelCodeNew") String modelCodeNew) throws Exception {
        List<String> resultList = new ArrayList<String>();
        try {
            resultList = testDrivingService.dispatchCarList(dispatchObject, modelCodeNew);
            return new Response<List<String>>(ResultMsgConstants.RESULT_CODE_SUCCESS, resultList, "");
        } catch (Exception e) {
            logger.error("查询状态发生异常", e);
            return new Response<>(ResultMsgConstants.RESULT_CODE_ERROR, e.getMessage());
        }
    }

    @RequestMapping(value = "/carList", method = RequestMethod.GET, produces = "application/json;charset=UTF-8")
    @ApiOperation(value = "顾问确认-车辆列表", notes = "顾问确认-车辆列表")
    @CrossOrigin
    public Response<List<String>> carList(@RequestParam("driveId") String driveId,
                                          @RequestParam("modelCodeNew") String modelCodeNew) throws Exception {
        List<String> resultList = new ArrayList<String>();
        try {
            resultList = testDrivingService.carList(driveId, modelCodeNew);
            return new Response<List<String>>(ResultMsgConstants.RESULT_CODE_SUCCESS, resultList, "");
        } catch (Exception e) {
            logger.error("查询状态发生异常", e);
            return new Response<>(ResultMsgConstants.RESULT_CODE_ERROR, e.getMessage());
        }
    }

    @RequestMapping(value = "/engineer", method = RequestMethod.GET, produces = "application/json;charset=UTF-8")
    @ApiOperation(value = "鉴赏工程师列表", notes = "鉴赏工程师列表")
    @CrossOrigin
    public Response<List<TmUsers>> engineer(@RequestParam("licenseNo") String licenseNo) throws Exception {
        List<TmUsers> resultList = new ArrayList<TmUsers>();
        try {
            resultList = testDrivingService.engineer(licenseNo);
            return new Response<List<TmUsers>>(ResultMsgConstants.RESULT_CODE_SUCCESS, resultList, "");
        } catch (Exception e) {
            logger.error("查询鉴赏工程师列表发生异常", e);
            return new Response<>(ResultMsgConstants.RESULT_CODE_ERROR, e.getMessage());
        }
    }

    @RequestMapping(value = "/dispatch", method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
    @ApiOperation(value = "客服分拨", notes = "客服分拨")
    @CrossOrigin
    public Response<Map<String, Object>> dispatch(@RequestBody TtTestdrive ttTestdrive) throws Exception {
        Map<String, Object> result = new HashMap<String, Object>();
        try {
            result = testDrivingService.dispatch(ttTestdrive);
            return new Response<Map<String, Object>>(ResultMsgConstants.RESULT_CODE_SUCCESS, result, "");
        } catch (Exception e) {
            logger.error("客服分拨发生异常", e);
            return new Response<>(ResultMsgConstants.RESULT_CODE_ERROR, e.getMessage());
        }
    }

    @RequestMapping(value = "/managerList", method = RequestMethod.GET, produces = "application/json;charset=UTF-8")
    @ApiOperation(value = "企业号-经理查看试驾列表", notes = "企业号-经理查看试驾列表")
    @CrossOrigin
    public Response<PageInfo<TtTestdrive>> managerList(@RequestParam(required = false, defaultValue = "1") Integer pageNum,
                                                       @RequestParam(required = false, defaultValue = "10") String pageSize,
                                                       @RequestParam("userId") String userId,
                                                       @RequestParam("phone") String phone) throws Exception {
        Map<String, Object> query = new HashMap<String, Object>();
        try {
            query.put("pageNum", pageNum);
            query.put("pageSize", pageSize);
            query.put("wxUserId", userId);
            query.put("phone", phone);
            PageInfo<TtTestdrive> resultList = testDrivingService.managerList(query);
            return new Response<PageInfo<TtTestdrive>>(ResultMsgConstants.RESULT_CODE_SUCCESS, resultList, "");
        } catch (Exception e) {
            logger.error("查询预约发生异常", e);
            return new Response<>(ResultMsgConstants.RESULT_CODE_ERROR, e.getMessage());
        }
    }

    @RequestMapping(value = "/dealer", method = RequestMethod.GET, produces = "application/json;charset=UTF-8")
    @ApiOperation(value = "接单选择销售店列表", notes = "接单选择销售店列表")
    @CrossOrigin
    public Response<List<TmDealer>> dealer(@RequestParam(required = false, defaultValue = "") String userId,
                                           @RequestParam(required = false, defaultValue = "") String phone) throws Exception {
        List<TmDealer> resultList = new ArrayList<TmDealer>();
        try {
            resultList = testDrivingService.dealer(userId, phone);
            return new Response<List<TmDealer>>(ResultMsgConstants.RESULT_CODE_SUCCESS, resultList, "");
        } catch (Exception e) {
            logger.error("查询销售店列表发生异常", e);
            return new Response<>(ResultMsgConstants.RESULT_CODE_ERROR, e.getMessage());
        }
    }

    @RequestMapping(value = "/counselor", method = RequestMethod.GET, produces = "application/json;charset=UTF-8")
    @ApiOperation(value = "首席顾问列表", notes = "首席顾问列表")
    @CrossOrigin
    public Response<List<TmUsers>> counselor(@RequestParam("dealerCode") String dealerCode) throws Exception {
        List<TmUsers> resultList = new ArrayList<TmUsers>();
        try {
            resultList = testDrivingService.counselor(dealerCode);
            return new Response<List<TmUsers>>(ResultMsgConstants.RESULT_CODE_SUCCESS, resultList, "");
        } catch (Exception e) {
            logger.error("查询首席顾问列表发生异常", e);
            return new Response<>(ResultMsgConstants.RESULT_CODE_ERROR, e.getMessage());
        }
    }

    @RequestMapping(value = "/manager", method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
    @ApiOperation(value = "经理接单", notes = "经理接单")
    @CrossOrigin
    public Response<Map<String, Object>> manager(@RequestBody TtTestdrive ttTestdrive) throws Exception {
        Map<String, Object> result = new HashMap<String, Object>();
        try {
            result = testDrivingService.manager(ttTestdrive);
            return new Response<Map<String, Object>>(ResultMsgConstants.RESULT_CODE_SUCCESS, result, "");
        } catch (Exception e) {
            logger.error("经理接单发生异常", e);
            return new Response<>(ResultMsgConstants.RESULT_CODE_ERROR, e.getMessage());
        }
    }

    @RequestMapping(value = "/unableToRespond", method = RequestMethod.GET, produces = "application/json;charset=UTF-8")
    @ApiOperation(value = "经理接单-无法响应", notes = "经理接单-无法响应")
    @CrossOrigin
    public Response<Map<String, Object>> unableToRespond(@RequestParam("driveId") String driveId) throws Exception {
        Map<String, Object> result = new HashMap<String, Object>();
        try {
            result = testDrivingService.unableToRespond(driveId);
            return new Response<Map<String, Object>>(ResultMsgConstants.RESULT_CODE_SUCCESS, result, "");
        } catch (Exception e) {
            logger.error("经理接单发生异常", e);
            return new Response<>(ResultMsgConstants.RESULT_CODE_ERROR, e.getMessage());
        }
    }

    @RequestMapping(value = "/counselorList", method = RequestMethod.GET, produces = "application/json;charset=UTF-8")
    @ApiOperation(value = "企业号-顾问查看试驾列表", notes = "企业号-顾问查看试驾列表")
    @CrossOrigin
    public Response<PageInfo<TtTestdrive>> counselorList(@RequestParam(required = false, defaultValue = "1") Integer pageNum,
                                                         @RequestParam(required = false, defaultValue = "10") String pageSize,
                                                         @RequestParam(required = false, defaultValue = "") String userId,
                                                         @RequestParam(required = false, defaultValue = "") String phone) throws Exception {
        Map<String, Object> query = new HashMap<String, Object>();
        try {
            query.put("pageNum", pageNum);
            query.put("pageSize", pageSize);
            if (!CheckUtil.NullOrEmpty(userId)) {
                query.put("wxUserId", userId);
            }
            if (!CheckUtil.NullOrEmpty(phone)) {
                query.put("phone", phone);
            }
            PageInfo<TtTestdrive> resultList = testDrivingService.counselorList(query);
            return new Response<PageInfo<TtTestdrive>>(ResultMsgConstants.RESULT_CODE_SUCCESS, resultList, "");
        } catch (Exception e) {
            logger.error("查询发生异常", e);
            return new Response<>(ResultMsgConstants.RESULT_CODE_ERROR, e.getMessage());
        }
    }

    @RequestMapping(value = "/confirmOrder", method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
    @ApiOperation(value = "顾问确认", notes = "顾问确认")
    @CrossOrigin
    public Response<Map<String, Object>> confirmOrder(@RequestBody TtTestdrive ttTestdrive) throws Exception {
        Map<String, Object> result = new HashMap<String, Object>();
        try {
            result = testDrivingService.confirmOrder(ttTestdrive);
            return new Response<Map<String, Object>>(ResultMsgConstants.RESULT_CODE_SUCCESS, result, "");
        } catch (Exception e) {
            logger.error("顾问确认发生异常", e);
            return new Response<>(ResultMsgConstants.RESULT_CODE_ERROR, e.getMessage());
        }
    }

    @RequestMapping(value = "/cancel", method = RequestMethod.GET, produces = "application/json;charset=UTF-8")
    @ApiOperation(value = "顾问确认-用户取消预约", notes = "顾问确认-用户取消预约")
    @CrossOrigin
    public Response<Map<String, Object>> cancel(@RequestParam("driveId") String driveId) throws Exception {
        Map<String, Object> result = new HashMap<String, Object>();
        try {
            result = testDrivingService.cancel(driveId);
            return new Response<Map<String, Object>>(ResultMsgConstants.RESULT_CODE_SUCCESS, result, "");
        } catch (Exception e) {
            logger.error("取消预约发生异常", e);
            return new Response<>(ResultMsgConstants.RESULT_CODE_ERROR, e.getMessage());
        }
    }

    @RequestMapping(value = "/engineerList", method = RequestMethod.GET, produces = "application/json;charset=UTF-8")
    @ApiOperation(value = "企业号-鉴赏工程师查看试驾列表", notes = "企业号-鉴赏工程师查看试驾列表")
    @CrossOrigin
    public Response<PageInfo<TtTestdrive>> engineerList(@RequestParam(required = false, defaultValue = "1") Integer pageNum,
                                                        @RequestParam(required = false, defaultValue = "10") String pageSize,
                                                        @RequestParam(required = false, defaultValue = "") String userId,
                                                        @RequestParam(required = false, defaultValue = "") String phone) throws Exception {
        Map<String, Object> query = new HashMap<String, Object>();
        try {
            query.put("pageNum", pageNum);
            query.put("pageSize", pageSize);
            if (!CheckUtil.NullOrEmpty(userId)) {
                query.put("wxUserId", userId);
            }
            if (!CheckUtil.NullOrEmpty(phone)) {
                query.put("phone", phone);
            }
            PageInfo<TtTestdrive> resultList = testDrivingService.engineerList(query);
            return new Response<PageInfo<TtTestdrive>>(ResultMsgConstants.RESULT_CODE_SUCCESS, resultList, "");
        } catch (Exception e) {
            logger.error("查询发生异常", e);
            return new Response<>(ResultMsgConstants.RESULT_CODE_ERROR, e.getMessage());
        }
    }
    
    @RequestMapping(value = "/goodsList", method = RequestMethod.GET, produces = "application/json;charset=UTF-8")
    @ApiOperation(value = "行前确认-物品列表", notes = "行前确认-物品列表")
    @CrossOrigin
    public Response<List<TtDriveGoods>> goodsList() throws Exception {
        List<TtDriveGoods> resultList = new ArrayList<TtDriveGoods>();
        try {
            resultList = testDrivingService.goodsList();
            return new Response<List<TtDriveGoods>>(ResultMsgConstants.RESULT_CODE_SUCCESS, resultList, "");
        } catch (Exception e) {
            logger.error("立即出发发生异常", e);
            return new Response<>(ResultMsgConstants.RESULT_CODE_ERROR, e.getMessage());
        }
    }
    
    @RequestMapping(value = "/start", method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
    @ApiOperation(value = "鉴赏工程师-立即出发", notes = "鉴赏工程师-立即出发")
    @CrossOrigin
    public Response<Map<String, Object>> start(@RequestBody List<TrDriveGoodsRelation> list) throws Exception {
        Map<String, Object> result = new HashMap<String, Object>();
        try {
            result = testDrivingService.start(list);
            return new Response<Map<String, Object>>(ResultMsgConstants.RESULT_CODE_SUCCESS, result, "");
        } catch (Exception e) {
            logger.error("立即出发发生异常", e);
            return new Response<>(ResultMsgConstants.RESULT_CODE_ERROR, e.getMessage());
        }
    }

    @RequestMapping(value = "/driveAgreement", method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
    @ApiOperation(value = "上传试驾协议", notes = "上传试驾协议")
    @CrossOrigin
    public Response<Map<String, Object>> driveAgreement(@RequestBody TestdrivePO testdrivePO) throws Exception {
        Map<String, Object> result = new HashMap<String, Object>();
        try {
            result = testDrivingService.driveAgreement(testdrivePO);
            return new Response<Map<String, Object>>(ResultMsgConstants.RESULT_CODE_SUCCESS, result, "");
        } catch (Exception e) {
            logger.error("上传协议发生异常", e);
            return new Response<>(ResultMsgConstants.RESULT_CODE_ERROR, e.getMessage());
        }
    }

    @RequestMapping(value = "/driveFinished", method = RequestMethod.GET, produces = "application/json;charset=UTF-8")
    @ApiOperation(value = "完成试驾", notes = "完成试驾")
    @CrossOrigin
    public Response<Map<String, Object>> driveFinished(@RequestParam("driveId") String driveId) throws Exception {
        Map<String, Object> result = new HashMap<String, Object>();
        try {
            result = testDrivingService.driveFinished(driveId);
            return new Response<Map<String, Object>>(ResultMsgConstants.RESULT_CODE_SUCCESS, result, "");
        } catch (Exception e) {
            logger.error("完成试驾发生异常", e);
            return new Response<>(ResultMsgConstants.RESULT_CODE_ERROR, e.getMessage());
        }
    }

    @RequestMapping(value = "/driveFinished", method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
    @ApiOperation(value = "新增试驾人", notes = "评价页面-新增试驾人")
    @CrossOrigin
    public Response<Map<String, Object>> addDriver(@RequestBody TtDriveInfo ttDriveInfo) throws Exception {
        Map<String, Object> result = new HashMap<String, Object>();
        try {
            result = testDrivingService.addDriver(ttDriveInfo);
            return new Response<Map<String, Object>>(ResultMsgConstants.RESULT_CODE_SUCCESS, result, "");
        } catch (Exception e) {
            logger.error("完成试驾发生异常", e);
            return new Response<>(ResultMsgConstants.RESULT_CODE_ERROR, e.getMessage());
        }
    }

    @RequestMapping(value = "/evaluate", method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
    @ApiOperation(value = "立即评价", notes = "立即评价")
    @CrossOrigin
    public Response<Map<String, Object>> evaluate(@RequestBody EvaluationPO evaluationPO) throws Exception {
        Map<String, Object> result = new HashMap<String, Object>();
        try {
            result = testDrivingService.evaluate(evaluationPO);
            return new Response<Map<String, Object>>(ResultMsgConstants.RESULT_CODE_SUCCESS, result, "");
        } catch (Exception e) {
            logger.error("评价发生异常", e);
            return new Response<>(ResultMsgConstants.RESULT_CODE_ERROR, e.getMessage());
        }
    }

    @RequestMapping(value = "/remind", method = RequestMethod.GET, produces = "application/json;charset=UTF-8")
    @ApiOperation(value = "预约提醒", notes = "预约日期T-1，发送提醒短信")
    @CrossOrigin
    public Response<String> remind() throws Exception {
        try {
            String result = testDrivingService.remind();
            return new Response<String>(ResultMsgConstants.RESULT_CODE_SUCCESS, result, "");
        } catch (Exception e) {
            logger.error("预约提醒发生异常", e);
            return new Response<>(ResultMsgConstants.RESULT_CODE_ERROR, e.getMessage());
        }
    }

    @RequestMapping(value = "/list", method = RequestMethod.GET, produces = "application/json;charset=UTF-8")
    @ApiOperation(value = "企业号-查看预约列表", notes = "企业号-查看预约列表")
    public Response<PageInfo<TtTestdrive>> qyList(@RequestParam(required = false, defaultValue = "1") Integer pageNum,
                                                  @RequestParam(required = false, defaultValue = "10") String pageSize,
                                                  @RequestParam(required = false, defaultValue = "") String userId,
                                                  @RequestParam(required = false, defaultValue = "") String phone) throws Exception {
        try {
            String flag = "";
            flag = testDrivingService.selectRelation(userId, phone);
            if (flag.equals("702")) {
                return managerList(pageNum, pageSize, userId, phone);
            } else if (flag.equals("703")) {
                return counselorList(pageNum, pageSize, userId, phone);
            } else if (flag.equals("704")) {
                return engineerList(pageNum, pageSize, userId, phone);
            }  else if (flag.equals("701")) {
                PageInfo<TtTestdrive> result = testDrivingService.oemList(pageNum, pageSize);
                return new Response<PageInfo<TtTestdrive>>(ResultMsgConstants.RESULT_CODE_SUCCESS, result, "");
            }else {
                return new Response<>(ResultMsgConstants.RESULT_CODE_ERROR, "查询发生异常");
            }
        } catch (Exception e) {
            logger.error("查询发生异常", e);
            return new Response<>(ResultMsgConstants.RESULT_CODE_ERROR, e.getMessage());
        }
    }
}
